#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cerr<<#x<<':'<<x<<endl
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N=1e6+5;
int n;
int cnt[2];
int f[N];
int dfs(int x){
    if(x==1) return 0;
    if(f[x]) return f[x];
    return f[x]=dfs(x/2)+dfs(x-x/2)+x;
}
signed main(){
    freopen("id.in","r",stdin);
    freopen("id.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        cnt[s[0]-'0']++;
    }
    cout<<dfs(cnt[0])+dfs(cnt[1]);
    return 0;
}

/*

#include<bits/stdc++.h>
#define endl '\n'
#define debug(x) cerr<<#x<<':'<<x<<endl
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int N=1e6+5;
int n;
int ch[N][2],cnt[N],dep[N],fa[N],val[N];
int root=1,tot=1;
int insert(string s){
    int p=1;
    for(auto x:s){
        if(!ch[p][x-'0']) ch[p][x-'0']=++tot,fa[tot]=p,val[tot]=x-'0',dep[tot]=dep[fa[tot]]+1;
        p=ch[p][x-'0'];
    }
    cnt[p]++;
    return p;
}
int lt[N],rt[N],idx,bro[N],siz[N];
int rk[N<<1];
void dfs(int x){
    lt[x]=++idx;
    siz[x]=cnt[x];
    rk[idx]=x;
    for(int i=0;i<=1;i++){
        if(!ch[x][i]) continue;
        dfs(ch[x][i]);
        if(!siz[ch[x][i^1]]) bro[ch[x][i]]=1;
        siz[x]+=siz[ch[x][i]];
    }
    rt[x]=++idx;
    rk[idx]=x;
}
pair<int,int> tree[N<<3];
#define ls p<<1
#define rs p<<1|1
inline void push_up(int p){
    tree[p]=min(tree[ls],tree[rs]);
}
void build(int p,int l,int r){
    tree[p]={1000000000,1000000000};
    if(l==r) return;
    int mid=(l+r)>>1;
    build(ls,l,mid);
    build(rs,mid+1,r);
    push_up(p);
}
void change(int p,int l,int r,int x,pair<int,int> v){
    if(l==r){
        tree[p]=v;
        return;
    }
    int mid=(l+r)>>1;
    if(x<=mid) change(ls,l,mid,x,v);
    else change(rs,mid+1,r,x,v);
    push_up(p);
}
pair<int,int> ask(int p,int l,int r,int ql,int qr){
    if(ql<=l&&r<=qr) return tree[p];
    int mid=(l+r)>>1;
    if(qr<=mid) return ask(ls,l,mid,ql,qr);
    else if(ql>mid) return ask(rs,mid+1,r,ql,qr);
    else return min(ask(ls,l,mid,ql,qr),ask(rs,mid+1,r,ql,qr));
}
int id[N];
bool cmp(int x,int y){
    return dep[x]>dep[y];
}
signed main(){
    freopen("id5.in","r",stdin);
    freopen("id.out","w",stdout);
    cin>>n;
    string s;
    for(int i=1;i<=n;i++){
        cin>>s;
        insert(s);
        id[i]=i;
    }
    dfs(1);
    build(1,1,idx);
    // for(int i=1;i<=tot;i++) debug(bro[i]),debug(cnt[i]);
    for(int i=1;i<=tot;i++) if(bro[i]&&cnt[i]){
        change(1,1,idx,lt[i],{dep[i],i});
        change(1,1,idx,rt[i],{dep[i],i});
    }
    sort(id+1,id+n+1,cmp);
    int ans=0;
    for(int i=1;i<=n;i++){
        int x=id[i];
        if(!cnt[x]) continue;
        if(siz[x]==1) continue;
        pair<int,int> res={1000000000,1000000000};
        if(ch[x][0]) res=min(res,ask(1,1,idx,lt[ch[x][0]],rt[ch[x][0]]));
        if(ch[x][1]) res=min(res,ask(1,1,idx,lt[ch[x][1]],rt[ch[x][1]]));
        int y=rk[res.second];
        debug(x),debug(y);
        ans+=dep[y]-dep[x];
        if(!cnt[y]){
            change(1,1,idx,lt[y],{1000000000,1000000000});
            change(1,1,idx,rt[y],{1000000000,1000000000});
        }
        if(!siz[y]){
            int z=ch[fa[y]][val[y]^1];
            bro[z]=1;
            if(cnt[z]){
                change(1,1,idx,lt[z],{dep[z],z});
                change(1,1,idx,rt[z],{dep[z],z});
            }
        }
    }
    cout<<ans;
    return 0;
}
*/